import { SimpleImage } from '../classes/upload';

export const mappingComponent = (form: Form, component: string, options: any) => {
  switch (component) {
    case 'select':
      form.select(options === undefined ? [] : options);
      break;
    case 'sc':
    case 'selectCheckbox':
      form.selectCheckbox(options === undefined ? [] : options);
      break;
    case 'radio':
      form.radio(options === undefined ? { 0: '否', 1: '是' } : options);
      break;
    case 'checkbox':
      form.checkbox(options === undefined ? [] : options);
      break;
    case 'switch':
      form.switch(options === undefined ? [] : options);
      break;
    case 'textarea':
      form.textarea();
      break;
    case 'editor':
      form.editor();
      break;
    case 'date':
      form.datePicker();
      break;
    case 'time':
      form.timePicker();
      break;
    case 'cascader':
      form.cascader(options === undefined ? [] : options);
      break;
    case 'range':
      form.rangePicker();
      break;
    case 'ig':
    case 'inputGroup':
      form.inputGroup([], options);
      break;
    case 'sm':
    case 'strengthMeter':
        form.strengthMeter();
        break;
    case 'region':
      form.region();
      break;
    case 'upload':
      form.upload(options === undefined ? new SimpleImage().name(form?.field).get() : options);
      break;
    case 'password':
      form.password();
      break;
    case 'number':
      form.number();
      break;
    case 'input':
      form.input();
      break;
    case 'hidden':
      form.hidden();
      break;
    default:
      form.input();
  }
  return form;
};

export const mappingField = (field: string, component: string, options: any) => {
  let type = 'input';
  if (component === 'clear') {
    return {
      type: type,
      options: options
    };
  }
  
  switch (field) {
    case 'password':
    case 'confirm_password':
      type = 'password';
      break;
    case 'content':
      type = 'textarea';
      break;
    case 'sex':
      options = options == undefined ? { 1: '男', 2: '女' } : options;
      type = 'radio';
      break;
    case 'age':
    case 'sort':
      type = 'number';
      break;
    case 'icon':
    case 'thumb':
      type = 'upload';
      options = options === undefined ? new SimpleImage(100).get() : options;
      break;
    case 'avatar':
    case 'head':
    case 'logo':
      type = 'upload';
      options = options === undefined ? new SimpleImage(200).get() : options;
      break;
    case 'start_time':
    case 'end_time':
    case 'begion_time':
      type = 'datePicker';
      break;
    case 'begion_end':
      type = 'rangePicker';
      break;
    case 'region':
      type = 'region';
      break;
    case 'status':
      options = options === undefined ? ['关闭', '开启'] : options;
      type = 'radio';
      break;
  }
  
  return {
    type: type,
    options: options
  };
};
